// 开发环境
// package cn.com.ctcloud.saas;
//
// import org.springframework.boot.SpringApplication;
// import org.springframework.boot.autoconfigure.SpringBootApplication;
//
/// **
// * 启动类
// */
// @SpringBootApplication
// public class CtSaaSPlatformApplication {
//
// public static void main(String[] args) {
// System.out.println("SpringBoot 启动成功!");
// SpringApplication.run(CtSaaSPlatformApplication.class, args);
// }
// }

// 打包环境
package cn.com.ctcloud.saas;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMethod;

import com.google.common.collect.Lists;

import cn.com.ctcloud.saas.core.utils.CTSaaSConstants;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.builders.ResponseMessageBuilder;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2 // springfox
@SpringBootApplication
@ServletComponentScan // 扫描Servlet
public class CtSaaSPlatformApplication extends SpringBootServletInitializer {
	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
		return builder.sources(CtSaaSPlatformApplication.class);
	}

	public static void main(String[] args) {
		SpringApplication.run(CtSaaSPlatformApplication.class, args);
	}

	@Bean
	public Docket api() {
		return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
				//				.paths(PathSelectors.any()) // 指定扫描哪些接口。PathSelectors.any()说明所有接口
				.paths(PathSelectors.ant("/api/**")).build().apiInfo(apiInfo()).useDefaultResponseMessages(false)
				.globalResponseMessage(RequestMethod.GET,
						Lists.newArrayList(
								new ResponseMessageBuilder().code(500).message("500 message")
										.responseModel(new ModelRef("Error")).build(),
								new ResponseMessageBuilder().code(403).message("Forbidden!").build()));
	}

	private ApiInfo apiInfo() {
		// 作者信息
		final Contact contact = new Contact("畅通数据", "http://www.ctcloud.com.cn", "CTCloud.com.cn");
		final ApiInfo apiInfo = new ApiInfo(CTSaaSConstants.SYSTEM_NAME + "接口文档", // 标题
				CTSaaSConstants.SYSTEM_NAME, // 描述
				CTSaaSConstants.SYSTEM_VERSION, // 版本
				"www.ctcloud.com.cn", //（不可见）条款地址
				contact, // 作者
				"畅通数据", // 版权所有
				"www.ctcloud.com.cn" // 公司网站链接
		);
		return apiInfo;
	}

}
